//------------------------------------------------------------------------------
#include "CChampText.h"
//------------------------------------------------------------------------------
QString CChampText::toString(QVariant value)
{
	switch(_dataType)
	{
		case CCommun::edtInt:
			return QString::number(value.toInt());
		case CCommun::edtDouble:
			return QString("%1").arg(value.toDouble(), 0, 'f', _nbDecimal);
		case CCommun::edtDate:
			return value.toDate().toString("dd/MM/yyyy");
		default:
			return value.toString();
	}
}
//------------------------------------------------------------------------------
bool CChampText::toBool(QString string)
{
	switch(_dataType)
	{
		case CCommun::edtInt:
			return string.toInt() == 0;
		case CCommun::edtDouble:
			return string.toDouble() == 0.0;
		default:
			break;
	}
	return string.isEmpty();
}
//------------------------------------------------------------------------------
QString CChampText::makeStyleSheet(EAttribut att, QString &toolTip)
{
	QString styleSheet="background-color: %1; color: %2; font-weight: %3; selection-background-color: %4; border: %5; border-radius: 3px;";
	QString bgColor="white;";
	QString color="black";
	QString weight="normal";
	QString selectionColor="#678DB2";
	QString border="none";
	
	if(att & atObligatoire)
	{
		bgColor="#FF6464";
		selectionColor="#678DB2";
		color="white";
		weight="bold";
	}
	if(att & atObligatoireConditionel)
	{
		bgColor="#6464FF";
		selectionColor="#FF6464";
		color="white";
		weight="bold";
		
		toolTip=getTextCondition();
	}
	if(att & atChampCalcul)
	{
		border="2px solid #008000";
		toolTip=QObject::tr("Champ calculé: ");
	}
	
	return styleSheet.arg(bgColor).arg(color).arg(weight).arg(selectionColor).arg(border);
}
//------------------------------------------------------------------------------